package com.basics.controller;

import com.basics.model.Response;
import com.basics.model.Response;
import com.basics.model.StudentInfomation;
import com.basics.service.StudentInfomationService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/StudentInfoSearch")
public class AdminStInEnquiryController {

    private Logger log = Logger.getLogger(UserAdminController.class);
    @Resource
    private StudentInfomationService studentInfomationService;

    @RequestMapping("/showAll")
    @ResponseBody
    public Response showUser(HttpServletRequest request) {
        log.info("显示全部学生信息");


        Integer count = studentInfomationService.getStudetCountNumber();
        Integer limit = Integer.valueOf(request.getParameter("limit"));
        Integer page = (Integer.valueOf(request.getParameter("page"))-1)*limit;
        List<StudentInfomation> studentInfomation = studentInfomationService.getAllStudentInfo(page,limit);
//        将获取到的数据放进response中返回前台
        Response response  = new Response();
        response.setCode("0");
        response.setCount(count);
        response.setMsg("");
        response.setData(studentInfomation);

        return response;
    }
}
